/**
 * Copyright &copy; 2019-2022 <a href="https://gitee.com/rit/zx-pm">zx-pm</a> All rights reserved.
 */
package com.zx.pm.modules.zx.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zx.pm.common.config.Global;
import com.zx.pm.common.persistence.Page;
import com.zx.pm.common.web.BaseController;
import com.zx.pm.common.utils.StringUtils;
import com.zx.pm.modules.zx.entity.YwLog;
import com.zx.pm.modules.zx.service.YwLogService;

/**
 * 业务日志Controller
 * @author forest
 * @version 2019-01-30
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/ywLog")
public class YwLogController extends BaseController {

	@Autowired
	private YwLogService ywLogService;
	
	@ModelAttribute
	public YwLog get(@RequestParam(required=false) String id) {
		YwLog entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = ywLogService.get(id);
		}
		if (entity == null){
			entity = new YwLog();
		}
		return entity;
	}
	
	@RequiresPermissions("zx:ywLog:view")
	@RequestMapping(value = {"list", ""})
	public String list(YwLog ywLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<YwLog> page = ywLogService.findPage(new Page<YwLog>(request, response), ywLog); 
		model.addAttribute("page", page);
		return "modules/zx/ywLogList";
	}

	@RequiresPermissions("zx:ywLog:view")
	@RequestMapping(value = "form")
	public String form(YwLog ywLog, Model model) {
		model.addAttribute("ywLog", ywLog);
		return "modules/zx/ywLogForm";
	}

	@RequiresPermissions("zx:ywLog:edit")
	@RequestMapping(value = "save")
	public String save(YwLog ywLog, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, ywLog)){
			return form(ywLog, model);
		}
		ywLogService.save(ywLog);
		addMessage(redirectAttributes, "保存业务日志成功");
		return "redirect:"+Global.getAdminPath()+"/zx/ywLog/?repage";
	}
	
	@RequiresPermissions("zx:ywLog:edit")
	@RequestMapping(value = "delete")
	public String delete(YwLog ywLog, RedirectAttributes redirectAttributes) {
		ywLogService.delete(ywLog);
		addMessage(redirectAttributes, "删除业务日志成功");
		return "redirect:"+Global.getAdminPath()+"/zx/ywLog/?repage";
	}

}